package com.njupt.towerssystem.controller;

import com.njupt.towerssystem.domain.ManageInfos;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/sys")
@CrossOrigin("*")
public class ManagerInfoCtrl {

    @RequestMapping("/userreg")
    public String reg(ManageInfos mi){
        System.out.println("到数据库进行数据注册");
        return "{\"userreg\":\"success\"}";
    }

    @RequestMapping("/login")
    public ManageInfos login(
            @RequestParam(required = false) String loginname,
            @RequestParam(required = false) String loginpwd,
            @RequestParam(required = false) String token
    ){
            if (loginname!=null){
                //用户名和密码
                if (loginname.equals("zs")&&loginpwd.equals("123")){
                    return ManageInfos.builder().userid(1).username("张三").loginpwd("123").loginname("zs")
                            .department("中铁建十一局六公司").createtime(new Date())
                            .lasttime(new Date()).tel("13000000001").token("12345678").build();
                }else {
                    return null;
                }
            }else {
                if (token.equals("12345678")){
                    return ManageInfos.builder().userid(1).username("张三").loginpwd("123").loginname("zs")
                            .department("中铁建十一局六公司").createtime(new Date())
                            .lasttime(new Date()).tel("13000000001").token("12345678").build();
                }else {
                    return null;
                }
            }
    }

    @RequestMapping("/userpower")
    public String setuserpower(int userid,int powerid,String isgrant){
        return "{\"powerset\":\"success\"}";
    }

    @RequestMapping("/insertPower")
    public String regpower(String relename){
        return "{\"powerreg\":\"success\"}";
    }
}
